package com.eims.sls_app.utils;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.eims.sls_app.dataaccess.AppObject;
import com.eims.sls_app.dataaccess.DtMatch;
import com.eims.sls_app.dataaccess.DtMatchBJDC;
import com.eims.sls_app.dataaccess.DtMatch_Basketball;
import com.eims.sls_app.dataaccess.Lottery;
import com.eims.sls_app.dataaccess.SelectedNumbers;
import com.eims.sls_app.dataaccess.Users;
import com.eims.sls_app.fragment.HallFragment;
import com.eims.sls_app.protocol.MD5;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ParseException;
import android.text.Spanned;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import bls.juejin.cn.R;

/**
 * App的 工具类
 * 
 * @author SLS003
 */
public class AppTools {
	
//	public static boolean choiceNum = false;
//	private static final boolean DEBUG = true;
	private static final String TAG = "AppTools";
//	public static String version;
//	public static int flag = 0;
//	// 用户
//	public static Users user = null;
//	public final static String userid= "306826";
//	public static AppObject appobject = new AppObject();
//	public static String[] Imagearray;
//	public static long width;
//	public static long height;
//	public static boolean isShow = true;
//	public static String imei = "";
//	public static int index = 1; // 第几次进入主界面
////	public static int schemeId; // 方案id
//	
//	public  static Spanned  showZongjiangInfo;
//	
//	// 测试用
//	public final static String MD5_key = "Q56GtyNkop97H334TtyturfgErvvv98a";
//	// key值，校验用
//	public static String key = MD5.md5(AppTools.MD5_key);
//	/** 百度推送的userId */
//	public static String push_userId = "";
//	/** 百度推送的channelId */
//	public static String push_channelId = "";
//	/** 百度推送的DeviceType */
//	public static String push_DeviceType = "3";
//	/** 0为离线 1为在线 */
//	public static String Status = "1";
//	public static String APP_NAME = "好球cp";// 软件名称
//	public static String SERVICE_PHONE = "4006-854-855";
//
//	public static long totalCount; // 用户所选总注数
//	public static List<SelectedNumbers> list_numbers; // 用户所投的集合
//	public static Lottery lottery; // 彩种对象
//	public static int bei = 1;
//	public static int qi; // 追多少期
//	public static String type; // 竞彩过关类型
//	public static String ball; // 竞彩过关数据---
//	public static boolean isCanBet = true; // 高频彩是否能投注
//	public static String followCommissionScale = ""; // 合买佣金比列
//	public static String followLeastBuyScale = ""; // 合买最少购买比列
//	public static List<List<DtMatch>> list_Matchs; // 比赛对阵信息
//	public static List<List<DtMatch_Basketball>> DtMatch_Basketball; // 比赛对阵信息
//	public static List<List<DtMatchBJDC>> list_Matchs_bjdc; // 比赛对阵信息
//	public static List<List<DtMatch>> list_singlepass_Matchs; // 单关比赛对阵信息
//	public static List<List<DtMatch_Basketball>> DtMatch_Basketball_single; // 篮球单关比赛对阵信息

	// 请求路径
	// public final static String url = "http://app.juejincai.com/";
	// 安卓的：http://hqcz.ucaipiao.com/PayConfirm2.aspx
	// 数据接口是：http://888.qcai888.cn/ajax/AppGateway.ashx
//	public final static String url = "http://888.qcai888.cn/";
//	public final static String path = url + "ajax/AppGateway.ashx";
//	public final static String Qpath = url + "clientsoft/download.aspx";
//
//	public final static String zPath = url
//			+ "Home/Room/OnlinePay/AlipayApp/Trade.aspx";
//	public final static String ylPath = url
//			+ "Home/Room/OnlinePay/YLAPP/purchase.aspx";
//	public final static String server_url = "https://msp.alipay.com/x.htm";
//	public final static String web_pay_url = "http://hqcz.ucaipiao.com/index.aspx?user_id=";
//	// 请求路径
//	public final static String pay_success = "http://hqcz.ucaipiao.com/Pay.aspx?";
//	// 获取订单号的路径
//	public final static String pay_outer_no = "http://hqcz.ucaipiao.com/Pay2.aspx?";
//	// 获取兴业订单号的路径
//		public final static String pay_outer_no_xinye = "http://hqcz.ucaipiao.com/Pay5.aspx?";
//	// 获取可付订单号的路径
//	public final static String pay_outer_no_kefu = "http://hqcz.ucaipiao.com/Pay3.aspx?";
//	public final static String pay_outer_no_shenzhen = "http://hqcz.ucaipiao.com/Pay6.aspx?";
//	public final static String pay_outer_saoma_shenzhen = "http://hqcz.ucaipiao.com/Pay7.aspx?";
//	// 支付同步接口
//	//public final static String pay_tongbu = "http://hqcz.ucaipiao.com/PayConfirm2.aspx";
//	public final static String pay_tongbu = "http://hqcz.ucaipiao.com/KPayConfirm.aspx";
//	
//	public final static String PAY_KEFU = "http://extman.kefupay.cn/tradition/WeChatpayment_mobile.action";
//	//public final static String pay_tongbu2 = "http://hqcz.ucaipiao.com/KPayConfirm.aspx";
//	// 合买人信息
//	public final static String AppGateway = url + "ajax/AppGateway.ashx";
//	// 实时比分
//	public final static String H5_Live = "http://m.iuliao.com/live";
//	public final static String H5_betfair = "http://m.iuliao.com/odds/betfair";
//	public final static String H5_liao = "http://m.iuliao.com/liao";
//	public final static String H5_odds = "http://m.iuliao.com/odds";
//
//	public static String serverTime = "";
//	public static String winToday = "";
//	public final static String[] names = { "opt", "auth", "info" };
//
//	// 标准版JC - 29时时彩 "72", "73", "28", "78", "83", "62", "74", "75", "39"
//	public final static String lotteryIds = "72, 73, 28, 78, 83, 62, 74, 75, 39";// "83,6,62,70,28,61,5,13,3,39,63,64,78,74,75,72,73,45";
//	// 彩种ID 对应 的 图片
//	public static Map<String, Integer> allLotteryLogo = null;
//	// 彩种ID 对应的 名称
//	public static Map<String, String> allLotteryName = null;
//	public static String lotterysId = "";// 用于保存所有的彩种位置
//
//	public static long sum_Income_Money = 0; // 总收入
//	public static long sum_Expense_Money = 0; // 总支出
//	public static long sum_Bonus_Money = 0; // 中奖
//
//	public static boolean isVibrator;
//	public static boolean isSensor;
//	public static String isPushKJ;
//	public static String isPushZJ;
//
//	public static final int BASE_ID = 0;
//	public static final int RQF_PAY = BASE_ID + 1;
//	public static final String VERSION = "version";
//	public static final String partner = "partner";
//
//	public static final String action = "action";
//	public static final String actionUpdate = "update";
//	public static final String data = "data";
//	public static final String platform = "platform";
//
//	public static final int Lottery_ALL = 1; // 个人中心 查看类型 为 全部
//	public static final int Lottery_WIN = 2; // 个人中心 查看类型 为 中奖
//	public static final int Lottery_WAIT = 3; // 个人中心 查看类型 为 待开奖
//	public static final int Lottery_FOLLOW = 4; // 个人中心 查看类型 为 追号
//	public static final int Lottery_CHIPPED = 5; // 个人中心 查看类型 为 合买
//
//	public static final int ERROR_SUCCESS = 0;
//	public static final int ERROR_UNLONGIN = -100;
//	public static final int ERROR_TOTAL = -102;
//	public static final int ERROR_MONEY = -134;
//
//	/** 绑定银行信息的类型 **/
//	public static final int BANK_TYPE = 1;
//	public static final int PROVINCE_TYPE = 2;
//	public static final int CITY_TYPE = 3;
//	public static final int ZHI_TYPE = 4;
//	public static final int QUESTION_TYPE = 5;
//	public static final int QUESTION_TYPE2 = 6;
//	public static final int MONEY_TYPE = 7;
//
//	public static ArrayList<Integer> level_star_list = null;
//	public static ArrayList<Integer> level_medal_list = null;
//	public static ArrayList<Integer> level_cup_list = null;
//	public static ArrayList<Integer> level_crown_list = null;
//	public static int currentScoring;
//	public static int totalScoring;
//	public static int totalConversionScoring;
//	public static int scoringExchangerate;
//	public static int optScoringOfSelfBuy;
//	
//	public static final String privatekey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCwvNG8bNzsFJNksjWcPcEjcaIoWIuIBkLhupKIL9b9Kara/wcBGUhvr0ogOym8yp4oUR02NOymL4rNKopNnGUoqD6CqyEebpWgsBx505OAsvomRPcpZimpDlX8Wp9TiURbDPjYj9hng9WCTvKK804ffIlzbVmBhLBuGVqzQog4VdcenqYtY6yzWR3APDhZ5JVDKWjmWKlPmd+ReNPtdVd1AwfOSZAZUouzTS67cxQeowYFCaheZBbV5nUY6fHVijErxudxvbJa6qprQOMFnbo1zvlTR/tHFq2nE+6g8XRjeEg29xxgNOzRGJZy+IlaYZwLlYJRbJ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/Q3dIV/WENWXBHe2aGY5KlSd6sCgYEAvr7+FgXUBSyik9Sa0feJ5bTyRvlhDEdFFy94EyGhjBiiYJ9npX+5Yq76iuAT0KSXtYrsss1lZezGhCrKRrH7ZEEZRTWCl59OljWiKXlTFT7cPHM3XsbHQpz+1AoweLkmeTFD50kYr48FLJUazazc0tW0fkAPD6Zz9BMSKJH8YDkCgYEAxTwMqvZmlg7JRa71jpuQDPFkN48zMEbbumktiXk9IwsBg00XTcdD7Z8j+E1D6jFHpUkOr70aHswt94k0BS1hjHplW+PYgYtul6J0SLhROwinpZrZqVgwX1O6DYeZ4HvVZ48NslaAt8zxirm4Nkw/POBH51lgpqkdahGKLG+hyEUCgYApchaDcoC/HxO0S13YgZDU+JwsD8Omh1Xb09SjU4tmhXPCyuAadcYySxLlWgr0Ks9MAwOrVjXSD8CStzl8Yu/cuMhk4Vue1l6dBMpXeKU02JPCDsbZMRfawYIdUJl3ocNaUfoPJzLV8p2NMljAl+7jYMv3IrQjEmffgMVRS2crAQKBgGelX4jquue3c7061PmQs5NdVE+U1ClM8zQbKx3WeCdzwWywlbepwx/HgDGSkk1gsL97TxLyJYmmrSjgfDEOlCnJAymCBtIKHvUvP1M23qop0vEWaG8k2H9r9VxY780VlHoX1vHUBXG9zkuVvd+DurIPG+xJqy5Rn+9CclT1DDjy";
//    public static final String key_kefu = "4297f44b13955235245b2497399d7a93";
//    
//    /**交易类型---------BEGIN*/
//    public static final String regesitor = "tb_Regesitor";//注册
//    
//    public static final String downLoadKeys = "tb_DownLoadKey";//下载
//    
//    public static final String verify = "tb_verifyInfo";//微信卡认证
//    
//    public static final String weiXinPay = "tb_WeixinPay";//微信支付
//    
//    public static final String orderConfirm = "tb_OrderConfirm";//订单状态查询
//    
//    public static final String changeRate = "xy_ChangeRate";//同步商户签约费率
//    
//    public static final String alipayVerify = "tb_alipayVerify";//支付宝卡认证
//    
//    public static final String aliPay = "tb_alipay";//支付宝支付
//    
//    public static final String zPayment = "zm_Payment";//代付
//
//	// 新增字段
//	public static String isSale = "";

	/** 设置ListView 的高度 */
	public static void setHight(BaseAdapter adapter, ListView listView) {
		int totalHeight = 0;
		for (int i = 0, len = adapter.getCount(); i < len; i++) {
			// listAdapter.getCount()返回数据项的数目
			View listItem = adapter.getView(i, null, listView);
			listItem.measure(0, 0); // 计算子项View 的宽高
			totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
		}
		ViewGroup.LayoutParams params = listView.getLayoutParams();
		// listView.getDividerHeight()获取子项间分隔符占用的高度
		params.height = totalHeight
				+ (listView.getDividerHeight() * (adapter.getCount() - 1));
		// params.height最后得到整个ListView完整显示需要的高度
		listView.setLayoutParams(params);
	}

	/**
	 * 设置战绩等级图片
	 */
	public static void setLevelList() {
		App.level_star_list = new ArrayList<Integer>();
		int[] star = { R.drawable.star_1, R.drawable.star_2, R.drawable.star_3,
				R.drawable.star_4, R.drawable.star_5, R.drawable.star_6,
				R.drawable.star_7, R.drawable.star_8, R.drawable.star_9 };

		for (int aStar : star) {
			App.level_star_list.add(aStar);
		}

		App.level_medal_list = new ArrayList<Integer>();
		int[] medal = { R.drawable.medal_1, R.drawable.medal_2,
				R.drawable.medal_3, R.drawable.medal_4, R.drawable.medal_5,
				R.drawable.medal_6, R.drawable.medal_7, R.drawable.medal_8,
				R.drawable.medal_9 };
		for (int aMedal : medal) {
			App.level_medal_list.add(aMedal);
		}
		App.level_cup_list = new ArrayList<Integer>();
		int[] cup = { R.drawable.cup_1, R.drawable.cup_2, R.drawable.cup_3,
				R.drawable.cup_4, R.drawable.cup_5, R.drawable.cup_6,
				R.drawable.cup_7, R.drawable.cup_8, R.drawable.cup_9 };
		for (int aCup : cup) {
			App.level_cup_list.add(aCup);
		}
		App.level_crown_list = new ArrayList<Integer>();
		int[] crown = { R.drawable.crown_1, R.drawable.crown_2,
				R.drawable.crown_3, R.drawable.crown_4, R.drawable.crown_5,
				R.drawable.crown_6, R.drawable.crown_7, R.drawable.crown_8,
				R.drawable.crown_9 };
		for (int aCrown : crown) {
			App.level_crown_list.add(aCrown);
		}
	}

	public static void setLogo() {
		App.allLotteryLogo = new LinkedHashMap<String, Integer>();
		/** 双色球 **/
		App.allLotteryLogo.put("5", R.drawable.log_lottery_ssq);
		/** 大乐透 **/
		App.allLotteryLogo.put("39", R.drawable.log_lottery_dlt);
		/** 11选5 **/
		App.allLotteryLogo.put("70", R.drawable.log_lottery_11x5);
		/** 时时彩 **/
		App.allLotteryLogo.put("28", R.drawable.log_lottery_ssc);
		/** 江西时时彩 **/
		App.allLotteryLogo.put("61", R.drawable.log_lottery_jxssc);
		/** 竞彩足球 **/
		App.allLotteryLogo.put("72", R.drawable.log_lottery_jczq);
		/** 北京单场 **/
		App.allLotteryLogo.put("45", R.drawable.log_lottery_bjdc);
		/** 竞彩篮球 **/
		App.allLotteryLogo.put("73", R.drawable.log_lottery_jclq);
		/** 江苏快3 **/
		App.allLotteryLogo.put("83", R.drawable.log_lottery_k3);
		/** 3D **/
		App.allLotteryLogo.put("6", R.drawable.log_lottery_3d);
		/** 胜负彩 **/
		App.allLotteryLogo.put("74", R.drawable.log_lottery_sfc);
		/** 任选九 **/
		App.allLotteryLogo.put("75", R.drawable.log_lottery_rx9);
		/** 排列三 **/
		App.allLotteryLogo.put("63", R.drawable.log_lottery_pl3);
		/** 排列五 **/
		App.allLotteryLogo.put("64", R.drawable.log_lottery_pl5);
		/** 七星彩 **/
		App.allLotteryLogo.put("3", R.drawable.log_lottery_qxc);
		/** 七乐彩 **/
		App.allLotteryLogo.put("13", R.drawable.log_lottery_qlc);
		/** 山东11选5 **/
		App.allLotteryLogo.put("62", R.drawable.log_lottery_11ydj);
		/** 广东11选5 **/
		App.allLotteryLogo.put("78", R.drawable.log_lottery_gd11x5);
		
		addlottery();
	}

	/* 要求的彩种的几种排序方式 */
	public static void addlottery() {
		App.allLotteryName = new LinkedHashMap<String, String>();
		if (App.lotterysId != null && !"".equals(App.lotterysId)) {
			String[] ids = App.lotterysId.split(",");
			for (int i = 0; i < ids.length; i++) {
				String name = LotteryUtils.getTitleText(ids[i]);
				App.allLotteryName.put(name, ids[i]);
			}
		} else {
			App.allLotteryName.put("竞彩足球", "72");
			App.allLotteryName.put("竞彩篮球", "73");
			App.allLotteryName.put("重庆时时彩", "28");
			App.allLotteryName.put("广东11选5", "78");
			App.allLotteryName.put("江苏快3", "83");
			App.allLotteryName.put("十一运夺金", "62");
			App.allLotteryName.put("胜负彩", "74");
			App.allLotteryName.put("任选九", "75");
			App.allLotteryName.put("大乐透", "39");
			App.allLotteryName.put("北京单场", "45");
			

			// allLotteryName.put("双色球", "5");
			// allLotteryName.put("江西11选5", "70");
			// allLotteryName.put("七星彩", "3");
			// allLotteryName.put("七乐彩", "13");
			// allLotteryName.put("排列三", "63");
			// allLotteryName.put("排列五", "64");
			// allLotteryName.put("3D", "6");
			//
			//
			//
			// allLotteryName.put("北京单场", "45");

			// allLotteryName.put("竞彩足球", "72");
			// allLotteryName.put("竞彩篮球", "73");
			// allLotteryName.put("北京单场", "45");
			// allLotteryName.put("双色球", "5");
			// allLotteryName.put("大乐透", "39");
			// allLotteryName.put("3D", "6");
			// allLotteryName.put("重庆时时彩", "28");
			// allLotteryName.put("江西时时彩", "61");
			// allLotteryName.put("江西11选5", "70");
			// allLotteryName.put("十一运夺金", "62");
			// allLotteryName.put("广东11选5", "78");
			// allLotteryName.put("江苏快3", "83");
			// allLotteryName.put("排列三", "63");
			// allLotteryName.put("排列五", "64");
			// allLotteryName.put("七星彩", "3");
			// allLotteryName.put("七乐彩", "13");
			// allLotteryName.put("胜负彩", "74");
			// allLotteryName.put("任选九", "75");
		}
	}

	/** 将Set进行排序 */
	public static List<String> sortSet(Set<String> set) {
		List<String> list = new ArrayList<String>();
		List<Integer> list1 = new ArrayList();
		// list.addAll(set);
		for (String str : set) {
			list1.add(Integer.parseInt(str));
		}
		Collections.sort(list1);
		for (int i = 0; i < list1.size(); i++) {
			int num = list1.get(i);
			String number = num + "";
			if (!set.contains(num + "")) {
				number = "0" + num;
			}
			list.add(number);
		}
		return list;
	}

	/** 将值转换成 毫秒 */
	@SuppressLint("SimpleDateFormat")
	public static long getTimestamp(String date) throws ParseException,
			java.text.ParseException {
		Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
		long time = date1.getTime();
		return time;
	}
	
	@SuppressLint("SimpleDateFormat") 
	public static String getDaString(){
		SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(new java.util.Date());
	}

	/** 根据年月 得到当月的共有几天 */
	public static int getLastDay(int year, int month) {
		Calendar time = Calendar.getInstance();
		time.clear();
		time.set(Calendar.YEAR, year); // year为 int
		time.set(Calendar.MONTH, month - 1);// 注意,Calendar对象默认一月为0
		int day = time.getActualMaximum(Calendar.DAY_OF_MONTH);// 本月份的天数
		return day;
	}

	/** 传入一个毫秒类型转成 mm:ss 的类型的字符串 */
	public static String formatDuring(long mss) {
		long days = mss / (1000 * 60 * 60 * 24);
		long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
		long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
		long seconds = (mss % (1000 * 60)) / 1000;
		String showDays = "0";
		String showHour = "0";
		String showMinutes = "0";
		String showSeconds = "0";

		if (days < 10) {
			showDays = "0" + days;
		} else {
			showDays = days + "";
		}
		if (hours < 10) {
			showHour = "0" + hours;
		} else {
			showHour = "" + hours;
		}
		if (minutes < 10) {
			showMinutes = "0" + minutes;
		} else {
			showMinutes = "" + minutes;
		}
		if (seconds < 10) {
			showSeconds = "0" + seconds;
		} else {
			showSeconds = "" + seconds;
		}

		if (mss > 1000 * 60 * 60 * 24)
			return showDays + "天" + showHour + "时";
		else if (mss > 1000 * 60 * 60)
			return showHour + "时" + showMinutes + "分";
		else if (mss > 1000 * 60)
			return showMinutes + "分" + showHour + "秒";
		else
			return showMinutes + "分" + showSeconds + "秒";
	}

	public static String getDate(JSONObject isusesInfo) {
		try {
			if (null != isusesInfo) {
				Log.i(TAG, "is" + isusesInfo);
				App.serverTime = isusesInfo.optString("serverTime");
				App.winToday = isusesInfo.optString("winToday");
				Log.i(TAG, "请求数据时，今日开奖id--  " + App.winToday);

				JSONArray array = new JSONArray(
						isusesInfo.getString("isusesInfo"));

				for (int i = 0; i < array.length(); i++) {
					if (array.get(i).toString().length() < 5) {
						continue;
					}
					JSONObject object = array.getJSONObject(i);
					if (null != object.toString()) {
						for (int j = 0; j < HallFragment.listLottery.size(); j++) {
							if (HallFragment.listLottery.get(j).getLotteryID()
									.equals(object.optString("lotteryid"))) {
								// 绑定值
								HallFragment.listLottery.get(j).setLotteryName(
										HallFragment.listLottery.get(j)
												.getLotteryName());
								HallFragment.listLottery.get(j).setIsuseId(object.optString("isuseId"));
								HallFragment.listLottery.get(j).setAddaward(
										object.optString("addaward"));
								HallFragment.listLottery
										.get(j)
										.setLotteryDescription(
												object.optString("Description"));
								HallFragment.listLottery.get(j)
										.setLotteryAgainst(
												object.optString("Against"));

								HallFragment.listLottery.get(j).setIsuseName(
										object.optString("isuseName"));// 当前期
								HallFragment.listLottery.get(j).setIsSale(
										object.optString("isSale"));
								HallFragment.listLottery.get(j).setStarttime(
										object.optString("starttime"));
								HallFragment.listLottery.get(j).setEndtime(
										object.optString("endtime"));
								HallFragment.listLottery
										.get(j)
										.setLastIsuseName(
												object.optString("lastIsuseName"));

								HallFragment.listLottery
										.get(j)
										.setLastWinNumber(
												object.optString("lastWinNumber"));
								HallFragment.listLottery
										.get(j)
										.setOriginalTime(
												object.optString("originalTime"));
								HallFragment.listLottery.get(j).setExplanation(
										object.optString("explanation"));
								long nowTime = 0;
								try {
									long endtime = AppTools
											.getTimestamp(HallFragment.listLottery
													.get(j).getEndtime());
									long originalTime = AppTools
											.getTimestamp(HallFragment.listLottery
													.get(j).getOriginalTime());

									long se = AppTools
											.getTimestamp(App.serverTime);

									nowTime = System.currentTimeMillis();

									HallFragment.listLottery.get(j)
											.setDistanceTime(
													endtime - se + nowTime);
									HallFragment.listLottery
											.get(j)
											.setDistanceTime2(
													originalTime - se + nowTime);
								} catch (Exception ex) {
									HallFragment.listLottery.get(j)
											.setDistanceTime(0);
									Log.i("x", "拿倒计时报错" + ex.getMessage());
									ex.printStackTrace();
								}
								String dtCanChase = object
										.optString("dtCanChaseIsuses");

								List<String> dt = new ArrayList<String>();
								if (dtCanChase.length() != 0) {
									JSONArray arr = new JSONArray(dtCanChase);

									for (int k = 0; k < arr.length(); k++) {
										JSONObject ob = arr.getJSONObject(k);
										dt.add(ob.optString("isuseId"));
									}
								}
								System.out.println("++++pppp+++++"
										+ HallFragment.listLottery.get(j)
												.getLotteryID());
								String detail = object.optString("dtMatch");
								JSONArray array2 = new JSONArray(new JSONArray(
										detail).toString());
								if (array2.length() != 0) {
									HallFragment.listLottery
											.get(j)
											.setDtmatch(
													array2.getJSONObject(0)
															.optString(
																	"guestTeam")
															+ "vs"
															+ array2.getJSONObject(
																	0)
																	.optString(
																			"mainTeam"));

								}

								HallFragment.listLottery.get(j)
										.setDtCanChaseIsuses(dt);
								System.out.println("+++++++++[[[[[["
										+ HallFragment.listLottery.get(j)
												.getDtmatch());
							}
						}
					}
				}
			}

		} catch (JSONException e) {
			e.printStackTrace();
			Log.d("HallActivity", "大厅得到数据出错：" + e.getMessage());
			return "-1001";
		} catch (Exception e) {
			e.printStackTrace();
			Log.d("HallActivity", "2大厅得到数据出错：" + e.getMessage());
			return "-1001";
		}
		setLotteryShow();
		return "0";
	}

	/** 自动登录 **/
	public static String doLogin(JSONObject item) {
		try {
			if ("0".equals(item.optString("error"))) {
				App.user = new Users();
				App.user.setUid(item.optString("uid"));
				App.user.setName(item.optString("name"));
				App.user.setRealityName(item.optString("realityName"));
				App.user.setBalance(item.optDouble("balance"));
				App.user.setFreeze(item.optDouble("freeze"));
				App.user.setEmail(item.optString("email"));
				App.user.setIdcardnumber(item.optString("idcardnumber"));
				App.user.setMobile(item.optString("mobile"));
				App.user.setMsgCount(item.optInt("msgCount"));
				App.user.setMsgCountAll(item.optInt("msgCountAll"));
				App.user.setHeadUrl("http://888.qcai888.cn/"+item.optString("headUrl"));
				App.user.setScoring(item.optInt("scoring"));
				App.user.setHandselAmount(item.optDouble("handselAmount"));
				App.user.setCode(item.optString("code"));
				Log.e("code",item.optString("code"));
				// // 用户密码 （没加密的）
				// AppTools.user.setUserPass(pass);
				return App.ERROR_SUCCESS + "";
			} else {
				if (App.DEBUG)
					Log.i(TAG, item.optString("msg"));
				return item.optString("error");
			}
		} catch (Exception ex) {
			if (App.DEBUG)
				Log.i(TAG, "登录异常---" + ex.getMessage());
			ex.printStackTrace();
			return "-110";
		}
	}

	// "5,39,6,63,64,3,13,74,75";
	/** 设置显示的值 **/
	public static void setLotteryShow() {
		for (int j = 0; j < HallFragment.listLottery.size(); j++) {
			if (HallFragment.listLottery.get(j).getExplanation() != null
					&& !HallFragment.listLottery.get(j).getExplanation()
							.equals("")) {
				HallFragment.listLottery.get(j).setExplanation(
						HallFragment.listLottery.get(j).getExplanation());
			} else {
				switch (Integer.parseInt(HallFragment.listLottery.get(j)
						.getLotteryID())) {
				case 5:
					HallFragment.listLottery.get(j).setExplanation("奖池2530万");
					break;
				case 39:
					HallFragment.listLottery.get(j).setExplanation("奖池2530万");
					break;
				case 83:
					HallFragment.listLottery.get(j).setExplanation("2元赢取￥240元");
					break;
				case 6:
					HallFragment.listLottery.get(j).setExplanation("简单3位赢千元");
					break;
				case 63:
					HallFragment.listLottery.get(j).setExplanation("3位数字赢千元");
					break;
				case 64:
					HallFragment.listLottery.get(j).setExplanation("2元赢取10万元");
					break;
				case 3:
					HallFragment.listLottery.get(j).setExplanation("奖池2530万");
					break;
				case 13:
					HallFragment.listLottery.get(j).setExplanation("30选7赢百万");
					break;
				case 74:
					HallFragment.listLottery.get(j).setExplanation("猜胜负赢500万");
					break;
				case 75:
					HallFragment.listLottery.get(j).setExplanation("猜胜负赢500万");
					break;
				case 72:
					HallFragment.listLottery.get(j).setExplanation("2串1倍投收益高");
					break;
				case 73:
					HallFragment.listLottery.get(j).setExplanation("玩2串1易中奖");
					break;
				case 28:
					HallFragment.listLottery.get(j).setExplanation(
							"每天120期   10分钟一期");
					break;
				case 62:
				case 82:
				case 68:
				case 70:
					HallFragment.listLottery.get(j).setExplanation(
							"每天78期  10分钟一期");
					break;
				case 69:
					HallFragment.listLottery.get(j).setExplanation("每日20:30开奖");
				case 87:
					HallFragment.listLottery.get(j).setExplanation(
							"每天84期   10分钟一期");
					break;
				default:
					break;
				}
			}
		}
	}

	public static float getDpi(Activity context) {
		DisplayMetrics metric = new DisplayMetrics();
		context.getWindowManager().getDefaultDisplay().getMetrics(metric);

		int width = metric.widthPixels; // 宽度（PX）
		int height = metric.heightPixels; // 高度（PX）

		float density = metric.density; // 密度（0.75 / 1.0 / 1.5）
		int densityDpi = metric.densityDpi; // 密度DPI（120 / 160 / 240）
		return density;
	}
	
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	

	/**
	 * 获取版本名称
	 * 
	 * @param context
	 * @return
	 */
	public static String getVerName(Context context) {
		String verName = "";
		try {
			verName = context.getPackageManager().getPackageInfo(
					"com.eims.sls_app.activity", 0).versionName;
			Log.i("版本号--->", verName);
		} catch (NameNotFoundException e) {
			Log.e("erro", e.getMessage());
		}
		return verName;
	}

	/**
	 * 改变字体的颜色
	 * 
	 * @param color
	 *            字体颜色
	 * @param content
	 *            内容
	 * @return
	 */
	public static String changeStringColor(String color, String content) {
		return "<font color='" + color + "'>" + content + "</FONT>";
	}
	public static String changeStringBoldColor(String color, String content) {
		return "<b><font color='" + color + "'> " + content + "</FONT></b>";
	}
	/**
	 * 当前期号是否截止
	 */
	public static boolean isIsuseNotExpired(Lottery mLottery) {
		return mLottery != null
				&& mLottery.getDistanceTime() > System.currentTimeMillis();
	}

	public static Lottery getLotteryById(String lotteryId) {
		Lottery mLottery = null;
		for (Lottery lottery : HallFragment.listLottery) {
			if (lottery.getLotteryID().equals(lotteryId)
					&& (isIsuseNotExpired(lottery))) {
				mLottery = lottery;
				break;
			}
		}
		return mLottery;
	}
	/**
	 * 获取网落图片资源
	 * @param url
	 * @return
	 */
	public static Bitmap getHttpBitmap(String url){
		URL myFileURL;
		Bitmap bitmap=null;
		try{
			myFileURL = new URL(url);
			//获得连接
			HttpURLConnection conn=(HttpURLConnection)myFileURL.openConnection();
			//设置超时时间为6000毫秒，conn.setConnectionTiem(0);表示没有时间限制
			conn.setConnectTimeout(6000);
			//连接设置获得数据流
			conn.setDoInput(true);
			//不使用缓存
			conn.setUseCaches(false);
			//这句可有可无，没有影响
			//conn.connect();
			//得到数据流
			InputStream is = conn.getInputStream();
			//解析得到图片
			bitmap = BitmapFactory.decodeStream(is);
			//关闭数据流
			is.close();
		}catch(Exception e){
			e.printStackTrace();
		}

		return bitmap;

	}
    
	public static  String removeTheBlankOfString(String str) {
	    if(str==null||str.equals(""));
	    int endPosition = str.length()-1;
	    for (int i = str.length()-1; i >= 0; i--) {
	        if(str.charAt(i)==' ')endPosition--;
	        else break;
	    }
	    return str.substring(0,endPosition+1);
	}
}
